$(function () {

    $("#submit").click(function() {
        var userName = $(".loginName").val();
        var passWord = $(".loginPassword").val();
        if (check($.trim(userName))) {
            alert("请输入手机号码");
            return false;
        }
        if (check($.trim(passWord))) {
            alert("请输入密码");
            return false;
        }
        if(!(/^1[3456789]\d{9}$/.test(userName))){
            alert("手机号码有误，请重填");
            return false;
        }

        var conditionData = {
            "phone":userName,//电话号码
            "password": passWord//密码
        };
        var conditionDataJSON = JSON.stringify(conditionData);
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: '/user/login3',
            data: conditionDataJSON,
            contentType: "application/json",
            cache: false,
            async: true,
            success: function (data) {
                if (data.falge=="ok"){
                    window.location.href ="/goods/index.html";
                }else {
                    alert("登录失败请联系管理人员！")
                }
                console.log(data);

            }
        })
        return true;
    })


    function check(s) {
        return (s == null || typeof (s) == "undefined" || s == "");
    }

    //去掉前后空格
    function trim(s) {
        return s.replace(/(^\s*)|(\s*$)/g, "");
    }

    /**
     * 电话号码校验
     * @returns {boolean}
     */
    function checkPhone(s){
        var phone = document.getElementById('phone').value;
        if(!(/^1[3456789]\d{9}$/.test(s))){
            alert("手机号码有误，请重填");
            return false;
        }
    }

})